package com.me.study.javaCore.rmi;

import com.me.study.javaCore.rmi.OrderService;
import com.me.study.javaCore.rmi.User;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

/**
 * JAVA RMI 学习：RMI 远程调用客户端 <p>
 *
 * @author ME
 * @date   2020/2/24
 */
public class TestRmiClient {

    public static void main(String[] args) {
        try {
            // 获取本地主机上的 注册服务
            Registry registry = LocateRegistry.getRegistry(8080);
            // 查找远程服务
            // OrderService orderService = (OrderService) registry.lookup("OrderService");

            OrderService orderService = (OrderService) Naming.lookup("//127.0.0.1:9999/OrderService");

            String response = orderService.queryOrderByUser(new User("Jack"));
            System.out.println(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
